home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacWorld 1999 July
/
Macworld (1999-07).dmg
/
Shareware World
/
Info
/
For Developers
/
Mops 3.4.sea
/
Quick Edit ƒ
/
Subject Glossary
/
Compiler
< prev
next >
Wrap
Text File
|
1996-01-14
|
12KB
|
285 lines
\ 14Jan96 DBH
( --
Left paren. Denotes the beginning of a comment. At least one
space must follow. End comment with a right paren ).
) --
Right paren. Denotes the end of a comment that was begun by ( .
\ -- Backslash. Will cause compiler to ignore the rest of that line.
(* ( -- ) Compiler Base
(* ... *) defines a multi-line comment, which can be very useful. Many
Pascal compilers use these symbols - I thought it better not to use
the C-style /* ... */ since */ already has a meaning.
A useful improvement to the typical Pascal implementation is to keep a
level count so that this kind of comment can be nested.
*) ( -- ) Compiler Base
See (* .
ENDLOAD Will cause compiler to ignore the rest of the file being loaded.
VECT cfa -- : name
Defines an execution variable that can hold and execute the cfa
of a Mops word. Executing the vect name will execute the cfa.
Can use -> at runtime to change.
STATE -- compile-state
This value is the compilation state of the Mops interpreter. A non-zero
value means that the definition of a word, method, or class is being compiled.
CSTATE -- b
This value is a boolean which is true while a class is being compiled. It is
analogous to state which is true while a colon word is being compiled.
?COMP --
Prints message: "compilation only" if not compiling, that is, if state is not
zero
[ --
So now [ and ] do double duty. If they follow a method selector, they cause a
late bind as in Neon. In any other context they turn compilation on and off.
$ -- n
Will compile the ensuing characters in the input stream as a hex
number.
LIT n --
A state-smart version of LITERAL. Corresponds to LITERAL in Fig-Forth or
original Neon, whereas our present LITERAL is Forth-83.
LITW n --
In Neon, ' (tick) was state-smart, following Fig-Forth. We have
now followed the Forth-83 and ANSI standards in replacing the
state-smart tick with the two state-dumb forms ' (which ticks the
next word in the input stream at run time, no matter what) and
['] which is immediate, must be used in a definition, and
compiles a literal fetch of the cfa of the following word.
' -- cfa : word compilation only
['] -- cfa : word runtime only
.ID ?cfa --
If addr looks like a cfa with a name, prints the name. If it
looks like a cfa without a name, prints "(no name)". Otherwise
doesn't print anything.
XTS{ -- : name1 name2 etc.
State-smart word to compile or stack a list of xts. Pulls words from stream,
until "}".
?#XTS n1 n2 --
Used to check that the right number of stacked cfas is being passed in.
: -- : name
Creates a dictionary entry for the next word in the input stream.
standard
; -- standard
For defining action handlers that cross module bounds. If a class is defined
in module1, but instantiated in module2 with action handlers in module2, define
handlers with :a ... ;a.
:A --
;A --
,EXEC cfa n --
State-smart execute. If used within a program definition, compiles the cfa as
a literal to be executed at runtime; otherwise executes it immediately. This
is not an immediate word. It is useful in building compiler words which
conditionally compile other words.
0, -- Compiles an empty cell.
, n -- Compiles 4-byte n into the next available dictionary address.
C, w -- Compiles 1-byte c into the next available dictionary address.
W, w -- Compiles 2-byte w into the next available dictionary address.
Forward -- : name
Creates a word which is to be defined later with :f, the special colon compiler
for forward-referenced Yerk words, because :f makes the word behave like a
colon definition. If you forget to define a forward-referenced word, the word
issues the message: "Unresolved forward reference to: AWORD at address: XXXX"
and aborts. To forward reference an object, define a value having the same
name as the object-to-be. Later create the object as you would normally.
:F -- : name
Begins compilation of a word which was previously
forward-referenced. :f creates a headerless entry for the word
and then patches the previous entry to point to the newly
compiled definition. Forward-referencing is useful when a word
is to be used before it can be defined. You end the compilation
with ;f.
;F --
Ends compilation of a word which was defined with :f. See forward.
IMMEDIATE -- standard
INLINE{ -- : word ... }
Commences a piece of inline code. Allows faster execution. We assume that
inline code chunks will be fairly short, and are to be optimized for speed.
EVALUATE addr len --
ANSI standard. Makes the passed-in string the input stream for
interpretation or compilation, until it is exhausted.
EX-GEN cfa --
"Execute general". Executes the word with the given cfa. The word may be
anything. It is executed by compiling it into a temporary buffer, then
branching there. Slower than Execute, but unlike Execute, will really execute
anything.
EX-METHOD obj cfa --
Executes the method with the given cfa, using the given object.
EXECUTE cfa -- standard
EXN cfa n --
is to EX-GEN what (COMPN) is to (COMP). It has the additional parameter n
which is action code for -> ++> etc. Because this can be called from EX-GEN
(which may be executing a prefix op), we use the alternate execution buffer
ExBuf1.
INTERPRET
is the interpretation loop. Words from the input stream are interpreted
until the input is exhausted.
INTRP1 -- : word Interprets one word/number from the input stream.
PATCHES_DONE --
If you ever need to patch instructions, call this when you're finished. It
flushes the instruction cache if necessary to make sure that the new
instructions will really be executed. PATCH and (PATCH) call it already, so if
you are using these, you don't need to call Patches_done.
POSTPONE --
In this system, compilation is done by executing the compilation handler for
the word in question. POSTPONE must therefore be immediate, and compile the
right code into the client definition. This code consists of a literal push of
the POSTPONEd word's cfa, then a call to (COMP).
QUIT -- standard
TYPE{ -- : name1 name2 etc.
TYPE{ defines a Pascal-like enumerated type. At this stage we don't give a
name to the "type" as such, as we can't do anything really sensible with it.
However later we can optionally load the ENUM-TYPE class which is rather more
Pascal-like. But even without that, the enumeration is useful by itself.
{ --
Used to begin list of local variables and named input parameters. Note
that the compiler willfirst search this list, so these names take
precedence over other names in the dictionary.
TRAV cfa parm --
Traverses the dictionary, passing each cfa and the parm to the passed-in
proc.
TRAV-FROM cfa parm addr --
As for TRAV, but starts from the first word whose lfa is below or at the
given address.
TRAVERSE ?
RESERVE n -- Allots the next n bytes in the dictionary and erases them.
REVEAL -- Makes the current name visible again. See hide.
NAME? addr -- addr b
Returns True if the passed-in addr appears to be a cfa with a corresponding
valid name field.
OBJ? obj? -- obj? class | -- ^obj? 0
General test for an object. Not completely rigorous, so we shouldn't use
it in a TRAV, but pretty good nevertheless. If it is an object, the class
is left in theClass. We do assume the passed-in value may not be a legal
address at all.
OBJCFA? cfa -- cfa b
Returns true if the cfa refers to a dictionary object. Note: this won't
work for a heap object, since we rely on the unique handler code for
objects being there, and it won't be for heap objects. But this is the
only way to get a really rigorous check, which we need for TRAV. We assume
cfa is really a cfa.
HERE -- addr Returns the next available dictionary location.
HIDE --
Replace Smudge in Neon. HIDE hides the last dictionary header so that FIND
won't find it. REVEAL brings it back again. Use this if you want the
previous use of the name, i.e. if you DON'T want recursion.
L>NAME ?
latest -- nfa-1 A value. Leaves the nfa-1 of the last defined word.
LINK> ?
N>COUNT nfa -- addr len
Leaves the address and length of a name field, suitable for use by "type".
N>LINK ?
>BODY ?
>CLASS obj -- class | -- 0
Converts an object address to its class address. Returns zero if the
passed-in address isn't an object address. Needs to work for heap as well
as dictionary objects. The test is very unlikely (maybe 1/2**24) to
indicate a non-object as being an object. Without tagged storage we can't
be absolutely sure. To save time we don't do a conservative check on ^obj
actually being a legal address (unlike CFA?), apart from checking that it
is even, which is a very quick check. This means we may crash if an even
but illegal address is passed in. The presumption is that it really is an
object address, and that anything else is an (unlikely) error.
>ClassCfa obj -- class | -- 0
As for >CLASS, but if the class is exported from a module and you are
executing in the main dictionary, it gives the cfa of the imported word,
without accessing the module. This can be useful if you just want to
identify a class without needing all the class info. If you are executing
in the module, however, you will get the cfa of the class in the module.
The general rule is that the returned cfa will always be the same as if you
had just ticked the classname, wherever you are executing.
>HDLR ?
>LINK ?
>NAME cfa -- nfa Returns the name field address (nfa) for the given cfa.
NAME> ?
ENDTRAV? -- b
A value. May be set from within a trav handler to terminate the trav.
fence -- addr
A value. Leaves the address below which forget will not operate.
FIND str-addr -- cfa flag | -- F
Forth-83/ANSI standard. As in Neon, calls the vectored uFind first, then
simply returns if uFind returns a non-zero n. In all cases, if the search
succeeds, addr' is the cfa of the found dictionary entry, and n is -1 for a
non-immediate word and 1 for an immediate word. If the search fails, n is
zero and addr' is the same as str-addr.
FORGET -- : word
Deletes the word from the dictionary and ALL entries above it (i.e., in
higher memory). Issues message "in protected dictionary" if the word is
below fence, and aborts.
DEFINED? -- addr n : word
Defined as MWORD FIND. Does a FIND on the next word in the input stream.
DOES> --
Defines the runtime action of a word defined with <builds.
<BUILDS -- : name
We retain <BUILDS to be used in conjunction with DOES> rather than
following the standard and using CREATE. This is because CREATEd words
have the data right at the cfa, while DOES> words have to have a pointer to
the DOES> code. So rather than waste space in CREATEd words or do a
complicated kludge during compilation, we use <BUILDS.
DP -- addr
A value. Leaves the address of the next memory location above the
dictionary.
CONTEXT -- addr
CREATE -- : name
This is now Forth-83/ANSI. Creates a dictionary header using the next word
in the input stream. If this new word is executed, it returns its pfa.
What we actually do is to call HEADER, then add in the appropriate handler
code.
ALIGN-DP -- If the DP is odd, adds one to it.
ALLOT n --
Reserves n additional bytes for the code field of the last defined
dictionary entry.
CELLS #cells -- #bytes
Given the number of cells, returns the number of bytes required (#bytes = 4
x #cells).
CFA? cfa? -- cfa? b Checks if cfa? could really be a CFA.
CLASS? cfa? -- cfa? b Returns true if the cfa refers to a class.
1CELL ( -- 4 ) Compiler Base
Not ANSI, but useful. A constant which returms
the width of one cell.